function isProtected(node, editor) {
	return editor.dom.getParent(node, '[contenteditable="false"]');
}

const confineDeleteBlock = (editor) => {
	// 阻止删除受保护区块
	editor.on('keydown', async function(e) {
		let range = editor.selection.getRng();
		let currentNode = range.startContainer;
		let isHasMatch = !!currentNode.data && currentNode.data?.match(/\uFEFF/);
		if (editor.dom.hasClass(editor.selection.getNode(), 'locked')) e.preventDefault();
		if ((e.ctrlKey || e.metaKey) && e.keyCode === 88) e.preventDefault();
		if (e.keyCode === 8 && !e.ctrlKey && !e.altKey) {
			if (!!isHasMatch && range.startOffset === 1) {
				e.preventDefault();
			}
		}
		if (e.keyCode === 46 && !e.ctrlKey && !e.altKey) {
			e.preventDefault();
		}
	});
	// 阻止右键删除
	editor.on('contextmenu', function(e) {
		let selection = editor.selection.getNode();
		isProtected(selection, editor) && e.preventDefault();
	});
}

export default { confineDeleteBlock }